export const setItem = (key, vlaue) => {
  // 把数组和对象类型的数据转换成JSON格式
  if (typeof vlaue === 'object') {
    vlaue = JSON.stringify(vlaue)
  }
  window.localStorage.setItem(key, vlaue)
}

export const getItem = key => {
  const data = window.localStorage.getItem(key)
  // 获取数据然后进行转换,之所以不用if 是因为类型难以判断
  try {
    return JSON.parse(data)
  } catch (err) {
    return data
  }
}

export const removeItem = key => {
  window.localStorage.removeItem(key)
}
